<?php
include_once '../../lib/config.php';
include_once '../../lib/db.php';
include_once '../../lib/utils/tag.php';
include_once '../../model/prestasipelanggaran.php';

$proc = $_REQUEST['proc'];

switch ($proc){
	case "perpel-table":
		$key = $_POST['key'];
		$orderby = $_POST['orderby'];
		include '../../view/admin/prestasipelanggaran/tableList.php';
		break;
		
	case "add-modal":
		include '../../view/admin/prestasipelanggaran/perpel_add.php';
		break;
		
	case "perpel-add":
		$id = $_POST['perpel_id'];
		$jenis = $_POST['perpel_jenis'];
		$bidang = $_POST['perpel_bidang'];
		
		if ($id === '' || is_null($id)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi ID Prestasi/Pelanggaran")); return ;
		}
		if ($jenis=== '' || is_null($jenis)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi Jenis Prestasi/Pelanggaran")); return ;
		}
		if ($bidang === '' || is_null($bidang)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi Bidang Prestasi/Pelanggaran")); return ;
		}
		
		$ex = perpel_add($id, $jenis, $bidang);
		echo json_encode(array('error'=> !$ex, 'msg'=> mysql_innodb_error(mysql_errno())));
		break;
		
	case "edit-modal":
		$perpel_id = $_POST['perpel_id'];
		include '../../view/admin/prestasipelanggaran/perpel_edit.php';
		break;
		
	case "perpel-edit":
		$id = $_POST['perpel_id'];
		$jenis = $_POST['perpel_jenis'];
		$bidang = $_POST['perpel_bidang'];
		
		if ($id === '' || is_null($id)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi ID Prestasi/Pelanggaran")); return ;
		}
		if ($jenis=== '' || is_null($jenis)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi Jenis Prestasi/Pelanggaran")); return ;
		}
		if ($bidang === '' || is_null($bidang)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi Bidang Prestasi/Pelanggaran")); return ;
		}
		
		$ex = perpel_update($id,$jenis,$bidang);
		echo json_encode(array('error'=> !$ex, 'msg'=> mysql_innodb_error(mysql_errno())));
		break;
	case "perpel-delete":
		$perpel_id = $_POST['perpel_id'];
		$ex = perpel_delete($perpel_id);
		echo json_encode(array('error'=> !$ex, 'msg'=> mysql_innodb_error(mysql_errno())));
}



